import Attr from "../../goods/GoodsDatas";
export default function GoodsAttrReducer(state = Attr, action) {
    let AttrData = state.GoodStr //商品属性
    let BrandManageData = state.BrandManage //品牌管理
    let GoodsData = state.GoodsManage   //商品管理
    let LabelData = state.GoodsLabel   //商品管理
    switch (action.type) {
        case 'AttrADD':
            AttrData.push(action.payload)
            // console.log("111111111111111111111111", copyData);
            return { ...state, GoodStr: AttrData }
        case 'AttrEDIT':
            AttrData.forEach((el, i) => {
                if (el.id === action.id) {
                    AttrData.splice(i, 1, action.payload)
                }
            })
            return { ...state, GoodStr: AttrData }
        case 'AttrDEL':
            AttrData.forEach((el, index) => {
                if (el.id === action.id) {
                    AttrData.splice(index, 1)
                }
            });
            return { ...state, GoodStr: AttrData }
        // 品牌管理
        case 'BRAND_ADD':
            BrandManageData.push(action.payload)
            return { ...state, BrandManage: BrandManageData }
        case 'BRAND_EDIT':
            BrandManageData.forEach((el, i) => {
                if (el.id === action.id) {
                    BrandManageData.splice(i, 1, action.payload)
                }
            })
            return { ...state, BrandManage: BrandManageData }
        case 'BRAND_DEL':
            BrandManageData.forEach((el, index) => {
                if (el.id === action.id) {
                    BrandManageData.splice(index, 1)
                }
            });
            return { ...state, BrandManage: BrandManageData }
        // 商品管理
        case 'GOODS_ADD':
            GoodsData.push(action.payload)
            return { ...state, GoodsManage: GoodsData }
        case 'GOODS_EDIT':
            GoodsData.forEach((el, i) => {
                if (el.id === action.id) {
                    GoodsData.splice(i, 1, action.payload)
                }
            })
            return { ...state, GoodsManage: GoodsData }
        case 'GOODS_DEL':
            GoodsData.forEach((el, index) => {
                if (el.id === action.id) {
                    GoodsData.splice(index, 1)
                }
            });
            return { ...state, GoodsManage: GoodsData }
        case 'GOODS_SheL':
            console.log(action.id, action.tags);
            GoodsData.forEach((el, index) => {
                if (el.id === action.id) {
                    el.tags = action.tags
                }
            });
            console.log("GoodsData", GoodsData);
            return { ...state, GoodsManage: GoodsData }

        // 商品标签
        case 'LABEL_ADD':
            LabelData.push(action.payload)
            return { ...state, GoodsLabel: LabelData }
        case 'LABEL_EDIT':
            LabelData.forEach((el, i) => {
                if (el.id === action.id) {
                    LabelData.splice(i, 1, action.payload)
                }
            })
            return { ...state, GoodsLabel: LabelData }
        case 'LABEL_DEL':
            LabelData.forEach((el, index) => {
                if (el.id === action.id) {
                    LabelData.splice(index, 1)
                }
            });
            return { ...state, GoodsLabel: LabelData }
        default:
            return { ...state }
    }
}